package com.lyw.common.response;

import com.lyw.common.exception.BizCodeEnum;

public class ObjectRestResponse<T> extends BaseResponse {

    T data;

    public ObjectRestResponse() {
    }

    public ObjectRestResponse data(T data) {
        this.setData(data);
        return this;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static ObjectRestResponse ok(Object data) {
        return (new ObjectRestResponse()).data(data);
    }

    public static ObjectRestResponse ok(String message) {
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        objectRestResponse.setMessage(message);
        return objectRestResponse;
    }

    public static ObjectRestResponse ok(String message, Object data) {
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        objectRestResponse.setMessage(message);
        objectRestResponse.setData(data);
        return objectRestResponse;
    }

    public static ObjectRestResponse ok() {
        return new ObjectRestResponse();
    }

    public static ObjectRestResponse error(int statusCode, String message) {
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        objectRestResponse.setStatus(statusCode);
        objectRestResponse.setMessage(message);
        return objectRestResponse;
    }

    public static ObjectRestResponse error(String message) {
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        objectRestResponse.setStatus(BizCodeEnum.UNKNOW_EXCEPTION.getCode());
        objectRestResponse.setMessage(message);
        return objectRestResponse;
    }
}
